package com.xiaodu.acer.phoneplay.common.rx.subscriber;

import android.content.Context;

import com.xiaodu.acer.phoneplay.common.exception.BaseException;

import io.reactivex.disposables.Disposable;
import library.base.BaseView;

/**
 * 带进度的Subcriber
 * Progress需要Activity或者Fragment的context
 *
 * @param <T> context
 */
public abstract class ProgressSubcriber<T> extends ErrorHandlerSubscriber<T> {


    private BaseView mView;

    public ProgressSubcriber(Context context, BaseView view) {
        super(context);
        this.mView = view;
    }


    public boolean isShowProgress() {
        return true;
    }


    @Override
    public void onSubscribe(Disposable d) {
        if (isShowProgress()) {
            mView.showLoading();
        }
    }

    @Override
    public void onComplete() {
        mView.dismissLoading();
    }

    @Override
    public void onError(Throwable e) {
        super.onError(e);
        e.printStackTrace();

        BaseException baseException = mErrorHandler.handleError(e);
        mView.showError(baseException.getDisplayMessage());

    }

}
